package com.sgam.utils;


import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.codehaus.jackson.JsonParser;
import org.codehaus.jackson.JsonProcessingException;
import org.codehaus.jackson.map.DeserializationContext;
import org.codehaus.jackson.map.JsonDeserializer;


public class CustomDateDeserializer extends JsonDeserializer<Date>
{

	@Override
	public Date deserialize(JsonParser jsonparser, DeserializationContext deserializationcontext)  throws IOException, JsonProcessingException {
		
		SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy");
        String date = jsonparser.getText();
        
        if ( date == null || date.length() == 0 ) return null; // return null for empty string 
        
        try {
            return format.parse(date);
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
	}
 
}